package com.liuyou.duck2;

public abstract class Duck {
    protected FlyBehavior flyBehavior;

    public abstract void display();

    public void speak() {
        System.out.println("鸭子嘎嘎嘎");
    }

    public void swim() {
        System.out.println("鸭子游泳");
    }


    public void fly() {
        if (flyBehavior != null) {
            flyBehavior.fly();
        }
    }

/*    public Duck setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
        return this;
    }*/

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }
}
